'''
Created on 12.09.2009

@author: ankstoo
'''
       
class ImplementationConfig(object):
    """
        Represents config for service implementation
    """
    module = None
    className = None
    remote = None
    remoteAddress = None
    params = None

    def __init__(self, **kwargs):
        self.module = kwargs["module"]
        self.className = kwargs["className"]
        self.remote = kwargs["remote"]
        self.remoteAddress = kwargs["remoteAddress"]
        self.params = kwargs["params"]
        
    def isEqual(self, config):
        if self.remote <> config.remote:
            return False
        if self.remote:
            return self.remoteAddress == config.remoteAddress
        else:
            return self.module == config.module and self.className == config.className and self.params == config.params 


class ServiceProviderConfig(object):
    """
    """
    
    implementations = {}
    
    def add(self, serviceName, implementationConfig):
        self.implementations[serviceName] = implementationConfig
        
    def registerServices(self, serviceProvider):
        for name, impl in self.implementations.items():
            serviceProvider.registerService(name, impl)
    
    def update(self, implementations):
        self.implementations.update(implementations)
        
    def __init__(self, data = None):
        object.__init__(self)
        if data:
            self.update(data)
            

from pygs.config import serviceProviderConfig

defaultServiceProviderConfig = ServiceProviderConfig(serviceProviderConfig)